fix: compute file_size_bytes from the live stride, not PAGE_SIZE (#94) - #129
Merged
Conversation
`Chisel::file_size_bytes` and `Stats.file_size_bytes` both multiplied
`PageIo::page_count` by the hardcoded `PAGE_SIZE`. That count is in
stride-units, and an encrypted database runs at `ENC_PAGE_SIZE` (8232)
from birth, so every encrypted database under-reported its own on-disk
size by 0.49% — 40 MB at one million pages. `open_existing` already got
this right in its `FileSizeMismatch` arithmetic and even names the
hazard in a comment; the two public accessors did not.
Adds `TransactionManager::file_stride()` and multiplies by it at both
sites, so the value now matches `stat(2)` for plaintext and encrypted
databases alike — which is what `Stats.file_size_bytes` ("Raw size of
the database file on disk") and README ("Physical size of the database
file in bytes") have always promised.
The new test asserts against `fs::metadata(path).len()` rather than a
computed constant: PAGE_SIZE arithmetic can only agree with stat in the
plaintext case, so the encrypted arm fails on the old code and the
plaintext arm catches an over-correction in the other direction.
Closes #94.
This was referenced Jul 29, 2026
🚦 Bench results: PR vs main
Per-scenario detail (4 metrics × cells)document-store
mutation-log
ycsb-a
ycsb-b
|
This was referenced Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #94 (CRYPTO-5, BUG/correctness).
The defect
Chisel::file_size_bytesandStats.file_size_bytesboth didpage_count.saturating_mul(PAGE_SIZE as u64). ButPageIo::page_countreturns stride-units, and an encrypted database is re-strided to
ENC_PAGE_SIZE(8232) at open — so both public accessors under-reportedevery encrypted database's size by 0.49%, unbounded in absolute terms
(40 MB of error at one million pages).
open_existingalready computes this correctly for itsFileSizeMismatcharithmetic and its comment names the exact hazard:
The two public accessors just never got the same treatment.
The fix
Adds
TransactionManager::file_stride()— an infallible in-memory read ofPageIo::stride(), mirroring howopen_existingreaches it — andmultiplies by that at both call sites. Docs on
Chisel::stats,Chisel::file_size_bytesandStats::file_size_bytesupdated to saypage_count × strideand name both strides.No behaviour change for plaintext databases: stride is
PAGE_SIZEthere.Test
file_size_bytes_matches_stat_for_both_stridesasserts both accessorsequal
fs::metadata(path).len(), for a plaintext and an encrypted database,after growing each past the superblock region.
Asserting against
stat(2)rather than a computed constant is what makesthe test load-bearing:
PAGE_SIZEarithmetic can only agree with stat inthe plaintext case. Counterfactual — reverting just the
file_size_bytesline toPAGE_SIZE:(132 pages × 8192 vs × 8232.) The plaintext arm guards the other direction.
Verification
cargo test682 passing,cargo clippy --all-targets -- -D warningsclean,cargo fmt --checkclean.First of a stacked series addressing #94–#103.